<?php

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of persona
 *
 * @author informatica
 */
class Persona extends Controlador {
    
    function __construct() {
        parent::__construct();
        Session::init();
        $logeado = Session::get('logeado');
        $role = Session::get('role');
        if(!$logeado || $role != 'owner'){
            Session::destroy();
            header('location: '.URL.'login');
            exit;
        }
         $this->view->js = array('persona/js/default.js');
     
    }
    
    public function nuevo(){
        $this->view->municipios = $this->modelo->seleccionarMunicipios();
        $this->view->render('persona/nuevo');
    }
    
    public function index(){
        $this->view->listaPersona = $this->modelo->listarPersonas();
        $this->view->render('persona/index');
    }
    
    public function editar($id){
        $this->view->municipios = $this->modelo->seleccionarMunicipios();
        $this->view->persona = $this->modelo->listarPersonaIndividual($id);
        $this->view->render('persona/editar');
    }
    
    public function crear(){
       $data = array();
       $data['nacionalidad'] = $_POST['nacionalidad'];
        $data['cedula'] = $_POST['cedula'];
       $data['nombre'] = $_POST['nombre'];
       $data['direccion'] = $_POST['direccion'];
       $data['telefono'] = $_POST['telefono'];
        $data['parroquia'] = $_POST['parroquia'];
       
       $this->modelo->crear($data);
       header('location:' . URL .'persona');
    }
    
     public function guardarEditar($id){
       $data = array();
       $data['nacionalidad'] = $_POST['nacionalidad'];
        $data['cedula'] = $_POST['cedula'];
       $data['nombre'] = $_POST['nombre'];
       $data['direccion'] = $_POST['direccion'];
       $data['telefono'] = $_POST['telefono'];
        $data['parroquia'] = $_POST['parroquia'];
       $data['id'] = $id;
       $this->modelo->guardarEditar($data);
       header('location:' . URL .'persona');
    }
    
    public function eliminar($id) {
        $this->modelo->eliminar($id);
        header('location:' . URL .'persona');
    }
    
    public function cargarParroquias($id){
        $this->modelo->cargarParroquias($id);
    }
    
}

?>
